/*
Commented By: Marco Taubmann
Based On: http://www.linuxgazette.net/issue41/lopes/lcalc.htm
File Name: bmmsvSQL.flex
To Create: > ./bin/jflex bmmsvSQL.flex
*/

/* --------------------------Usercode Section------------------------ */ 
package DBSystem.analyze;

import java_cup.runtime.*;

%%

/* -----------------Options and Declarations Section----------------- */
%type java_cup.runtime.Symbol

/* The name of the class JFlex will create will be SQLexer.
   Will write the code to the file SQLexer.java.
*/
%class SQLexer

/*
The current line number can be accessed with the variable yyline
and the current column number with the variable yycolumn.
*/
%line
%column 

/* Will switch to a CUP compatibility mode to interface with a CUP
generated parser.
*/
%cupsym Sym
%cup

/*
Declarations
Code between %{ and %}, both of which must be at the beginning of a line, will
be copied letter to letter into the lexer class source.  Here you declare
member variables and functions that are used inside scanner actions.
*/
%{

  /* To create a new java_cup.runtime.Symbol with information about the current
     token, the token will have no value in this case. */
  private Symbol symbol(int type) {
    return new Symbol(type, yyline, yycolumn);
  }

  /* Also creates a new java_cup.runtime.Symbol with information about the
     current token, but this object has a value. */
  private Symbol symbol(int type, Object value) {
    return new Symbol(type, yyline, yycolumn, value);
  }

%} 

/*
Macro Declarations

These declarations are regular expressions that will be used latter in the
Lexical Rules Section.
*/ 
WHITE_SPACE = [ \f\n\r\t]+
INTEGER_TEXT = ([1-9][0-9]*)|0
DOUBLE_TEXT = (([1-9][0-9]*)|0)\.([0-9]*)
CHAR_TEXT = [a-zA-Z0-9\[\\\^\$\.\|\?\*\+\(\)\{\}\f\n\r\t]
IDENTIFIER = [a-zA-Z0-9_]*
DATATYPE = INT|DOUBLE|CHAR
STRING_START = [\'\"]
STRING_TEXT = ([^\'\"\r\n]|\\\'|\\\")*		/* singleline, with out ', ", but \" and \' is allowed. */
STRING_END = [\'\"]


%%
/* ------------------------Lexical Rules Section---------------------- */

/*
This section contains regular expressions and actions, i.e. Java code, that
will be executed when the scanner matches the associated regular expression. */

/* YYINITIAL is the state at which the lexer begins scanning.  So these regular
expressions will only be matched if the scanner is in the start state
YYINITIAL. */

<YYINITIAL> {

{WHITE_SPACE} 		{ }
"SELECT"			{return symbol(Sym.SELECT);}
"CREATE"			{return symbol(Sym.CREATE);}
"DROP"				{return symbol(Sym.DROP);}
"TABLE"				{return symbol(Sym.TABLE);}
"INSERT"			{return symbol(Sym.INSERT);}
"INTO"				{return symbol(Sym.INTO);}
"VALUES"			{return symbol(Sym.VALUES);}
"*"					{return symbol(Sym.ASTERISK);}
"FROM"				{return symbol(Sym.FROM);}
";"					{return symbol(Sym.SEMI);}
"("					{return symbol(Sym.LBRACK);}
")"					{return symbol(Sym.RBRACK);}
","					{return symbol(Sym.KOMMA);}

{DATATYPE}			{return symbol(Sym.DTYPE, yytext());}
{DOUBLE_TEXT}		{return symbol(Sym.DOUBLE, yytext());}
{INTEGER_TEXT}		{return symbol(Sym.INT, yytext());}
{CHAR_TEXT}			{return symbol(Sym.CHAR, yytext());}
{IDENTIFIER}		{return symbol(Sym.ID, yytext());}
}